﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace GameVer1
{
    public class Menu
    {
        #region Attribute
        private int _X;
        public int X
        {
            get { return _X; }
            set { _X = value; }
        }
        private int _Y;
        public int Y
        {
            get { return _Y; }
            set { _Y = value; }
        }
        private Texture2D[] _UnitTexture;
        public Texture2D[] UnitTexture
        {
            get { return _UnitTexture; }
            set { _UnitTexture = value; }
        }
        private Vector2 _direction;
        public Vector2 Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }
        private int _timeSinceLastFrame;
        public int TimeSinceLastFrame
        {
            get { return _timeSinceLastFrame; }
            set { _timeSinceLastFrame = value; }
        }
        private int _timePerFrame;
        public int TimePerFrame
        {
            get { return _timePerFrame; }
            set { _timePerFrame = value; }
        }
        private int _currentFrame;
        public int CurrentFrame
        {
            get { return _currentFrame; }
            set { _currentFrame = value; }
        }
        private int _numberFrame;
        public int NumberFrame
        {
            get { return _numberFrame; }
            set { _numberFrame = value; }
        }
        private Point _SizeFrame;
        public Point SizeFrame
        {
            get { return _SizeFrame; }
            set { _SizeFrame = value; }
        }
        private Vector2 _speed;
        public Vector2 Speed
        {
            get { return _speed; }
            set { _speed = value; }
        }
        private Color _filterColor;
        public Color FilterColor
        {
            get { return _filterColor; }
            set { _filterColor = value; }
        }
        private Rectangle _coverRect;
        public Rectangle CoverRect
        {
            get { return _coverRect; }
            set { _coverRect = value; }
        }
        private int _StopY;
        public int StopY
        {
            get { return _StopY; }
            set { _StopY = value; }
        }
        private float scale;
        public float Scale
        {
            get { return scale; }
            set { scale = value; }
        }
        public SoundEffect soundEffect;
        public bool flag;
        #endregion
        #region Constructor
        public Menu()
        {
            X = 300;
            CurrentFrame = 0;
        }

        public Menu(Texture2D[] menuTexture,int stop,int frame)
        {
            CoverRect = new Rectangle(X, Y, menuTexture[0].Width, menuTexture[0].Height);
            flag = false;
            Scale = 1;
            X = 300;
            Y = -50;
            StopY = stop;
            CurrentFrame = frame;
            TimePerFrame = 40;
            TimeSinceLastFrame = 0;
            UnitTexture = new Texture2D[menuTexture.Length];
            for (int i = 0; i < menuTexture.Length; i++)
                UnitTexture[i] = menuTexture[i];
        }
        #endregion
        #region Menthod
        public void Update(GameTime gameTime,Game1 game1)
        {
            TimeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (TimeSinceLastFrame > TimePerFrame)
            {
                if (Y<=StopY)
                    Y += 10;
                if (flag == false && Y>=StopY)
                {
                    soundEffect = game1.Content.Load<SoundEffect>(@"Audio\Start");
                    soundEffect.Play();
                    flag = true;
                }
                TimeSinceLastFrame = TimeSinceLastFrame - TimePerFrame;
            }
            UpdateCoverRect();
        }

        public void Draw(SpriteBatch spriteBatch,float scale)
        {
             spriteBatch.Draw(UnitTexture[CurrentFrame], new Vector2(X, Y),
                   new Rectangle(0, 0, UnitTexture[CurrentFrame].Width, UnitTexture[CurrentFrame].Height), Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, (float)0.5);
        }
        public void UpdateCoverRect()
        {
            Rectangle temp = new Rectangle(X, Y, CoverRect.Width, CoverRect.Height);
            CoverRect = temp;
        }
        #endregion
    }
        
}
